import axios from '@/utils/request'
const TYPES = {
  'cashier': '收银',
  'finance': '财务',
  'personnel': '人事',
  'attendance': '考勤'
}

export default {
  Officer: {
    list: {
      list_filter: {
        'store.id': () => {
          return axios
            .get(`/manage/stores`)
            .then(res =>
              Object.assign({ __label: '门店' },
                ...res.data.map(v => { return { [v.id]: v.name } })))
        },
        type: Object.assign({ __label: '类型' }, TYPES),
        name: {
          expression: `entity.getUser().getUsername() matches ":value"`,
          label: '用户名',
          type: 'input'
        }
      },
      list_display: [
        { property: 'user', label: '用户' },
        'store',
        {
          property: 'type',
          label: '类型',
          component: {
            props: ['data'],
            data() {
              return {
                types: TYPES
              }
            },
            render(h) {
              return <span>{this.types[this.data]}</span>
            }
          }
        },
        { property: 'enabled', label: '是否激活' }
      ]
    },
    form: {
      fields: [
        'user',
        'store',
        'type',
        { property: 'enabled', default_value: true }
      ]
    }
  }
}

